#version 300 es
layout(location=0)in vec2 aVerPos;
layout(location=1)in vec2 aTexPos;
uniform mat4 uTexMat;//纹理矩阵
uniform float uRotRad;
uniform vec2 uFlipScale;
uniform bool uAutoTexPos;
out vec2 texPos;

void auto(){
    gl_Position = vec4(aVerPos, 0.0, 1.0);
    float sinRad=sin(uRotRad);
    float cosRad=cos(uRotRad);
    mat2 rotMatrix=mat2(
    cosRad, sinRad,
    -sinRad, cosRad
    );
    vec2 coord = uFlipScale * (aVerPos / 2.0 * rotMatrix) + 0.5;
    texPos = (uTexMat * vec4(coord, 0.0, 1.0)).xy;
}

void none(){
    gl_Position = vec4(aVerPos, 0.0, 1.0);
    texPos = (uTexMat * vec4(aTexPos, 0.0, 1.0)).xy;
}

void main() {
    if (uAutoTexPos){
        auto();
    } else {
        none();
    }
}